import java.util.Scanner;

public class Main {
    //方法的使用
    //使用方法，判断是否是闰年
    public static boolean isLeapYear(int year) {
        if(((year % 4 == 0 && year % 100 != 0) || year % 400 ==0)) {
            return true;
        }else {
            return false;
        }
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int year = scanner.nextInt();

        if (isLeapYear(year)) {
            System.out.println("是闰年");
        }else {
            System.out.println("不是闰年");
        }
    }

    //实现一个两个整数相加的方法
    public static int sum(int n , int m) {
        return m + n;
    }

    public static void main2(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(sum(10, 20));


    }

    //用方法调用，实现1! + 2! + 3! + 4! + 5!
    public static int fac1(int n) {
        System.out.println("计算n的阶乘中n! = " + n);
        int result = 1;
        for(int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }

    public static void main3(String[] args) {
        int sum = 0;
        for(int i = 1; i <= 5; i++) {
            sum += fac(i);
        }
        System.out.println("sum = " + sum);
    }


    //方法重载
    public static void main4(String[] args) {
        int a = 2;
        int b = 3;

        double d = 4.6;
        double c = 4.7;
        System.out.println(add(a,b));
        System.out.println(add(d,c));
        System.out.println(add(a,d,c));
    }
    public static int add(int x, int y) {
        return x + y;
    }
    public static double add(double i , double y) {
        return i + y;
    }
    public static double add(int t, double g, double l) {
        return t + g + l;
    }

    //求3个整数
    public static int max(int a, int b) {
        return a > b ? a : b;
    }
    public static int max(int a, int b, int c) {
        int tmp = max(a,b);
        return max(tmp , c);
    }

    public static void main5(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        System.out.println(add(a, b));
        System.out.println(add(add(a, b), c));
    }

    //打印一组 都是整型的数据
    //可变参数编程
    public static void print(int... k) {
        for(int i = 0; i < k.length; i++) {
            System.out.print(k[i]);
        }
        System.out.println();
    }

    public static void main6(String[] args) {
        print(1,2);
        print(1,2,3);
        print(1,2,3,4,5,6);
    }

    //递归
    //递归求 N 的阶乘
    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        return n * fac(n-1);
    }

    public static void main7(String[] args) {
        int n = 5;
        int ret = fac(n);
        System.out.println(ret);
    }

    //按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4)
    public static void print1(int n) {
        if(n > 9) {
            print1(n / 10);
        }
        System.out.println(n % 10);
    }

    public static void main8(String[] args) {
        int n = 1234;
        print1(n);
    }

    //递归求 1 + 2 + 3 + ... + 10
    public static int sum(int n) {
        if(n == 1) {
            return 1;
        }
        return n + sum(n - 1);
    }

    public static void main9(String[] args) {
        int n = 10;
        System.out.println(sum(n));
    }

    //写一个递归方法，输入一个非负整数，返回组成它的数字之和. 例如，输入 1729, 则应该返回1+7+2+9，它的和是19
    public static int add1(int n) {
        if(n < 10) {
            return n;
        }
        return n % 10 + add1(n / 10);
    }

    public static void main10(String[] args) {
        int n = 1729;
        System.out.println(add1(n));
    }

    //求斐波那契数列的第 N 项
    public static int fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }

    public static void main11(String[] args) {
        int n = 3;
        System.out.println(fib(n));
    }
}